/**
 * Created by novem on 15/9/25.
 */
var url=getUrl();
window.onload=function(){
    var geolocation = new BMap.Geolocation();
    var html = "";
    var pager = 1;
//    geolocation.getCurrentPosition(function(r) {
//        var storage = window.localStorage;
//        storage.setItem("lng", r.point.lng);
//        storage.setItem("lat", r.point.lat);
//    });
    $.jsonp({
        url: 'http://'+url+'/api/mapline/mapline_list',
        data: {pager:pager},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            $.jsonp({
                url: 'http://'+url+'/api/common/slideshow/1/list',
                data: {type:1},
                callbackParameter: "callback",
                success: function (data, textStatus, xOptions) {
                    for(var i=0;i<data.length;i++){
                        $(".bacim"+i).attr("src",data[i].icon);
                    }
                },
                error: function (xOptions, textStatus) {}
            });
            $.each(data.arrays,function(index,ele){
                ele.dateNumber = Math.ceil(ele.dateNumber / (3600 * 24));
                var jumpurl = "jumptoLogin(" + "'xianlu_detail.html?id="+ele.id + "','index.html')";
                html += '<div onclick="' + jumpurl + '">' +
                '<div class="wrapper" id="photolist">' +
                    //'<a href="xianlu_detail.html?id=' + ele.id + '">' +
                    '<div class="ui-source-pic">' +
                    '<img src="' + ele.cover + '" height="260"class="round-pic" alt="">' +
                    '<i class="icons-flag">' + ele.dateNumber + '日游</i>' +
                    '<h3>' + ele.title + '</h3></div></a></div></div>';
                $(".more").html(html);
                $(".load-more11").text("");
                if(data.arrays.length<10){
                    $(".load-more").text("");
                    return;
                }
            });
            $(".load-more").on("click",function(){
                pager =pager+1;
                $.jsonp({
                    url: 'http://'+url+'/api/mapline/mapline_list',
                    data: {pager:pager},
                    callbackParameter: "callback",
                    success: function (data, textStatus, xOptions) {
                        $.each(data.arrays,function(index,ele){
                            ele.dateNumber = Math.ceil(ele.dateNumber / (3600 * 24));
                            var jumpurl = "jumptoLogin(" + "'xianlu_detail.html?id=" + ele.id + "','index.html')";
                            html+= '<div onclick="' + jumpurl + '">' +
                                '<div class="wrapper" id="photolist">' +
                                //'<a href="xianlu_detail.html?id=' + ele.id + '">' +
                                '<div class="ui-source-pic">' +
                                '<img src="' + ele.cover + '"height="260"class="round-pic" alt="">' +
                                '<i class="icons-flag">' + ele.dateNumber + '日游</i>' +
                                '<h3>' + ele.title + '</h3></div></a></div></div>';
                            $(".more").html(html);
                            $(".load-more11").text("");
                            if(data.arrays.length<10&&data.totalCount/pager<=10){
                                $(".load-more").text("");
                                return;
                            }
                        });
                    },
                    error: function (xOptions, textStatus) {}
                });
            });
        },
        error: function (xOptions, textStatus) {}
    });

    var mySwiper = new Swiper('.swiper-container',{
        pagination : '.swiper-pagination',
        //pagination : '#swiper-pagination1',
        loop : true,
        autoplay:3000,
        speed:800
    })
    //自动登录
    //jumpCallUserInfo();

    //alert($.getUrlParam("id"));
}
$(document).on("click",".ui-icon-search",function(){
    var name = $("#search").val();
    var html = "";
    var page = 1;
    if(name == ""){
      return;
    }
    $.jsonp({
        url: 'http://'+url+'/api/mapline/mapline_list',
        data: {searchMap:name,pager:page},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            if(data.arrays.length == 0){
               showToast("暂无搜索的内容");
               return;
            }
            $.each(data.arrays,function(index,ele){
                console.log(ele.id)
                ele.dateNumber = Math.ceil(ele.dateNumber / (3600 * 24));
                var jumpurl = "jumptoLogin(" + "'xianlu_detail.html?id=" + ele.id + "','index.html')";
                html +='<div onclick="' + jumpurl + '">' +
                    '<div class="wrapper" id="photolist">' +
                    //'<a href="xianlu_detail.html?id=' + ele.id + '">' +
                    '<div class="ui-source-pic">' +
                    '<img src="' + ele.cover + 'height="260""class="round-pic" alt="">' +
                    '<i class="icons-flag">' + ele.dateNumber + '日游</i>' +
                    '<h3>' + ele.title + '</h3></div></a></div></div>';
                $(".more").html(html);
                $(".load-more").text("");
                $(".load-more11").text("查看更多线路信息");
                if(data.arrays.length<10){
                    $(".load-more11").text("");
                    return;
                }
            });
            $(".load-more11").on("click",function(){
                page =page+1;
                console.log(page)
                $.jsonp({
                    url: 'http://'+url+'/api/mapline/mapline_list',
                    data: {searchMap:name,pager:page},
                    callbackParameter: "callback",
                    success: function (data, textStatus, xOptions) {
                        $.each(data.arrays,function(index,ele){
                            ele.dateNumber = Math.ceil(ele.dateNumber / (3600 * 24));
                            var jumpurl = "jumptoLogin(" + "'xianlu_detail.html?id=" + ele.id + "','index.html')";
                            html+= '<div onclick="' + jumpurl + '">' +
                                '<div class="wrapper" id="photolist">' +
                                //'<a href="xianlu_detail.html?id=' + ele.id + '">' +
                                '<div class="ui-source-pic">' +
                                '<img src="' + ele.cover + '"height="260"class="round-pic" alt="">' +
                                '<i class="icons-flag">' + ele.dateNumber + '日游</i>' +
                                '<h3>' + ele.title + '</h3></div></a></div></div>';
                            $(".more").html(html);
                            $(".load-more").text("");
                            if(data.arrays.length<10&&data.totalCount/pager<=10){
                                $(".load-more11").text("");
                                return;
                            }
                        });
                    },
                    error: function (xOptions, textStatus) {}
                });
            });
        },
        error: function (xOptions, textStatus) {}
    });
});

function onBackKeyDown() {
    jumpbyback(0,"");
}
